/*
 * @Author: 李无敌
 * @Date: 2025-07-25 17:00:51
 * @LastEditors: 李无敌
 * @LastEditTime: 2025-07-29 16:35:44
 * @FilePath: \nest-base\src\config\database.config.ts
 */
import { ConfigService } from '@nestjs/config';
import { MysqlConnectionOptions } from 'typeorm/driver/mysql/MysqlConnectionOptions';
import { join } from 'path';

export const createDatabaseConfig = (configService: ConfigService): MysqlConnectionOptions => ({
  type: 'mysql',
  host: configService.get('database.host') || 'localhost',
  port: configService.get('database.port') || 3306,
  username: configService.get('database.username') || 'root',
  password: configService.get('database.password') || 'root1234',
  database: configService.get('database.database') || 'nest_base',
  charset: configService.get('database.charset') || 'utf8mb4',
  timezone: configService.get('database.timezone') || '+08:00',
  synchronize: configService.get('database.synchronize') || false,
  logging: configService.get('database.logging') || true,
  entities: [join(__dirname, '../modules/**/*.entity{.ts,.js}')],
  migrations: [join(__dirname, '../../migrations/*{.ts,.js}')],
  migrationsRun: configService.get('database.migrationsRun') || true,
  migrationsTableName: configService.get('database.migrationsTableName') || 'migrations',
  extra: {
    connectionLimit: 10,
  },
}); 